﻿using SuperX.Common.Abstract;
using SuperX.Helper;
using SuperX.SuperSocket;
using SuperX.SuperSocket.Socket.Rpc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SuperX.DataCenterService.Listener
{
    public class RemoteServer : SingleBase<RemoteServer>
    {
        private RpcClient _rpcClient;
        public RemoteServer()
        {
            //_rpcClient = new RpcClient("127.0.0.1", 7668);
        }

        public void IsConnected()
        {
            if (_rpcClient == null) Init();
            if (!_rpcClient.IsConnect) _rpcClient.Reconnect();
        }

        public void Init()
        {
            _rpcClient = new RpcClient("127.0.0.1", 9100);
        }

        public object Invoke(RpcPara rpcPara, int timeout = 5000)
        {
            return _rpcClient.Call<object>(rpcPara, timeout);
        }

        public void Dispose()
        {
            _rpcClient.Dispose();
        }
    }
}
